package com.baitiaojun.auth.service.impl;

import com.baitiaojun.api.domain.auth.UserRole;
import com.baitiaojun.api.exception.ConditionException;
import com.baitiaojun.auth.mapper.UserRoleMapper;
import com.baitiaojun.auth.service.UserRoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Set;

/**
 * @类名 UserRoleServiceImpl
 * @描述 TODO
 * @作者 白条君
 * @创建日期 2022/12/7 21:07
 * @版本 1.0
 */
@Service
public class UserRoleServiceImpl implements UserRoleService {

    @Resource
    private UserRoleMapper userRoleMapper;

    @Override
    public Long getRoleIdByUserId(Long userId) {
        return userRoleMapper.selectRoleIdByUserId(userId);
    }

    @Override
    public String getRoleCodeByUserId(Long userId) {
        return userRoleMapper.selectRoleCodeByUserId(userId);
    }

    @Override
    public void addUserRole(UserRole userRole) throws ConditionException {
        int res = userRoleMapper.insertSelective(userRole);
        if (res == 0) {
            throw new ConditionException();
        }
    }
}
